import React, {Component} from 'react';
import {Form, Select, Input, Row, Col, Button, Modal, Upload, Icon} from 'antd'
import * as ReactDOM from "react-dom";
import ManagerBody from '../../components/ManagerBody';
import { FetchAPI } from '../../utils/fetch-middleware'

const Dragger = Upload.Dragger;

@Form.create()
export default class StudentAdd extends Component {

    state = {
        visible: false,
    }

    handleClick = (e) => {
        console.log('click ', e);
    }

    // 新生在线报道界面
    addTcd = (para) => {
        // let sendValue = JSON.parse(JSON.stringify(this.state.validDataSource));
        let sendValue = this.props.form.getFieldsValue();
        debugger;
        console.log(sendValue, 'values');
        FetchAPI('/api/student/update', 'POST', sendValue).then(result => {
            if(result.code === 'ACM0008'){
                Modal.success({
                    title: result.code,
                    content: '添加成功～',
                });
            } else {
                Modal.warning({
                    title: result.code,
                    content: result.message,
                });
            }
        }, err => {
            Modal.error({
                title: 'WRONG',
                content: '系统内部错误，请联系管理员',
            });
        });
    }

    handleOk = (e) => {
        console.log(e);
        this.addTcd();
        this.setState({
            visible: false,
        });
        //重置
        this.props.form.resetFields();

    }

    handleCancel = (e) => {
        console.log(e);
        this.setState({
            visible: false,
        });
    }

    render() {
        const {getFieldDecorator} = this.props.form;
        const props = {
            name: 'file',
            showUploadList: false,
            action: '/upload.do',
        };
        return (

            <Form className="student">
                <Form.Item
                    label="姓名"
                    labelCol={{span: 10}}
                    wrapperCol={{span: 14}}
                >
                    {getFieldDecorator('name', {
                            rules: [{
                                required: true, message: '请输入姓名!',
                            }],
                        }
                    )(
                        <Input style={{width: 140}}/>
                    )}
                </Form.Item>
                <Form.Item
                    label="身份证号"
                    labelCol={{span: 10}}
                    wrapperCol={{span: 14}}
                >
                    {getFieldDecorator('cardId', {
                            rules: [{
                                required: true, message: '请输入身份证号!',
                            }],
                        }
                    )(
                        <Input style={{width: 140}}/>
                    )}
                </Form.Item>
                <Form.Item
                    label="手机号"
                    labelCol={{span: 10}}
                    wrapperCol={{span: 14}}
                >
                    {getFieldDecorator('phone', {
                            rules: [{
                                required: true, message: '请输入手机号!',
                            }],
                        }
                    )(
                        <Input style={{width: 140}}/>
                    )}
                </Form.Item>
                <Form.Item
                    label="家长手机号"
                    labelCol={{span: 10}}
                    wrapperCol={{span: 14}}
                >
                    {getFieldDecorator('parPhone', {
                            rules: [{
                                required: true, message: '请输入家长手机号!',
                            }],
                        }
                    )(
                        <Input style={{width: 140}}/>
                    )}
                </Form.Item>
                <Form.Item
                    label="邮箱"
                    labelCol={{span: 10}}
                    wrapperCol={{span: 14}}
                >
                    {getFieldDecorator('email', {
                            rules: [{
                                required: true, message: '请输入邮箱!',
                            }],
                        }
                    )(
                        <Input style={{width: 140}}/>
                    )}
                </Form.Item>
                <center><Button onClick={this.handleOk} type="primary" size="large">确认报道</Button></center>
            </Form>
        );
    }
}
